package com.tjetc.dao.impl;

import com.tjetc.dao.PhotoDao;
import com.tjetc.domain.Photo;
import com.tjetc.utils.Db;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhotoDaoImpl  implements PhotoDao {
    @Override
    public void add(Photo photo) throws SQLException {
        Db.runner().update(Db.getConnection(), "insert into photo(mid,photopath) values(?,?)", photo.getMid(), photo.getPhotopath());
    }

    @Override
    public List<Photo> findByMid(int id) throws SQLException {
        return Db.runner0().query("select * from photo where mid=? ",
                new BeanListHandler<>(Photo.class),
                id);
    }

    @Override
    public void delByMid(int id) throws SQLException {
        Db.runner().update(Db.getConnection(),"delete from photo where mid=?",
                id);
    }
}
